#@head()
#define main()
<form class="layui-form" action="/consumption/addDetail" method="post">
    <input type="hidden" name="consumption_id" value="#(consumption_id??)" />
    <div class="layui-form-item">
        <label class="layui-form-label">收支类型</label>
        <div class="layui-input-block">
            <select name="col_id">
                <option value=""></option>
                #for(x : cols)
                    <option value="#(x.id)">#(x.col_name)</option>
                #end
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">收支金额</label>
        <div class="layui-input-block">
            <input type="number" name="money" placeholder="" autocomplete="off" class="layui-input" min="-1000000" max="1000000" step="1" lay-affix="number">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit lay-filter="demo-login">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(function(){
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.jquery;
        // 提交事件
        form.on('submit(demo-login)', function(data){

            let field = data.field;
            layer.alert(JSON.stringify(field), {
                title: '当前填写的字段值'
            });

            $.post("/consumption/addDetail",field,function(result){
                if(result.code===200){
                    var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                    parent.layer.close(index); // 再执行关闭
                    setTimeout(function () {
                        parent.location.reload();
                    },1000)
                }else{
                    layer.msg("插入失败！"+result.msg);
                }
            });
            return false; // 阻止默认 form 跳转
        });
    });
</script>
#end